#encoding: utf-8
from flask_wtf import Form
from wtforms import StringField, PasswordField, SubmitField, BooleanField, RadioField, TextAreaField
from wtforms.validators import  required, email, equal_to,length, regexp

class RegisterForm(Form):
    username = StringField("用户名:", validators=[required(message="请填写用户名！"), regexp('^[A-Za-z][A-Za-z0-9_.]*$', 0, message="用户名必须字母、数字、下划线、点！")])
    email = StringField("邮箱:", validators=[required(message="请填写邮箱地址！"), email(message="请填写合法邮箱地址！")])
    password = PasswordField("密码:", validators=[required(message="请填写密码！"), length(6, message="密码不能少于6个位")])
    confirmPassword = PasswordField("确认密码:", validators=[required(message="确认密码不能为空！"), equal_to("password", message="两次输入密码不一致！")])
    submit = SubmitField("注册")

class LoginForm(Form):
    email = StringField("邮箱:", validators=[required(message="请填写邮箱！"), email(message="请填写合法邮箱地址")])
    password = PasswordField("密码:", validators=[required(message="请填写密码！")])
    remember_me = BooleanField("记住我")
    submit = SubmitField("登录")

class CategoryForm(Form):
    name = StringField("分类名称", validators=[required(message="请填写分类名称！"), length(max=10, message="分类名称不能超过10个字！")])
    submit = SubmitField("保存")

class ArticleForm(Form):
    title = StringField("标题：", validators=[required(message="请填写标题！"), length(max=20, message="长度不能超过20个字！")])
    category_id = RadioField("分类：", choices=[], validators=[required(message="请选择分类！")])
    content = TextAreaField("内容：", validators=[required(message="请填写内容！")])
    submit = SubmitField("提交")

    def setCategory(self, category_list):
        pass
        self.category_id.choices = category_list